#ifndef USERINFO_H
#define USERINFO_H

#include <QString>
#include <QList>
#include <QTcpSocket>

class UserInfo
{
public:
    enum Status{
        DISCONNECTED,
        LOGIN,
        NEWGAME,
        JOINROOM,
        LOOK,
        INGAME
    };
private:
    struct User{
        QString username;
        QString password;
        Status status;
        QTcpSocket* socket;
        bool isAbnormalExit;
        int roomID;
        Status lastStatus;
    };

    QList<User> mUserList;
    void readUserData();
    void addUserData(QString user, QString pwd);
public:
    UserInfo();
    bool Register(QString user, QString pwd);
    bool Login(QString user, QString pwd, QTcpSocket* socket);
    int getRoom(QString user);
    void setRoom(QString user, int room);
    Status getStatus(QString user);
    Status getLastStatus(QString user);
    void setStatus(QString user, Status s);
    void setStatus(int index, Status s);
    void setStatus(QTcpSocket* socket, Status s);
    int indexOf(QString user);
    void setIsAbnormalExit(QString user, bool b);
    bool isAbnormalExit(QString user);
    void setSocket(QString user, QTcpSocket* socket);
    QString getUsername(QTcpSocket* socket);
};

#endif // USERINFO_H
